(*****************************************************************************
 * Delphi Plug-in Framework (DPF)
 * Copyright (C) 2006-2007 Tao Yuan
 *
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the
 * License at http://www.mozilla.org/MPL/
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.                                                               }
 *
 * The Initial Developer of the Original Code is Tao Yuan. Portions created by
 * Tao Yuan are Copyright (C) Tao Yuan (taoy.cn att gmail dott com)
 * All rights reserved.
 *****************************************************************************)
unit RDModel;

interface

uses
  SysUtils,
  Rcl,

  RDConsts,
  RDVersion;

type
  TModelDocumentation = class;
  TModelAttribute = class(TObject)
  private
    Fattributes: ILinkedList;
    Fdocumentation: TModelDocumentation;
    Fid: string;
    Fvalue: string;
  public
    constructor Create;
    destructor Destroy; override;
    property attributes: ILinkedList read Fattributes;
    property documentation: TModelDocumentation read Fdocumentation write
        Fdocumentation;
    property id: string read Fid write Fid;
    property value: string read Fvalue write Fvalue;
  end;

  TModelDocumentation = class(TObject)
  private
    Fcaption: string;
    Freferences: ILinkedList;
    Ftext: string;
  public
    constructor Create;
    property caption: string read Fcaption write Fcaption;
    property references: ILinkedList read Freferences;
    property text: string read Ftext write Ftext;
  end;

  TModelDocumentationReference = class(TObject)
  private
    Fcaption: string;
    Fpath: string;
  public
    property caption: string read Fcaption write Fcaption;
    property path: string read Fpath write Fpath;
  end;

  TModelExtension = class(TObject)
  private
    Fdocumentation: TModelDocumentation;
    Fid: string;
    Fparams: ILinkedList;
    FpluginId: string;
    FpointId: string;
  public
    constructor Create;
    destructor Destroy; override;
    property documentation: TModelDocumentation read Fdocumentation write
        Fdocumentation;
    property id: string read Fid write Fid;
    property params: ILinkedList read Fparams;
    property pluginId: string read FpluginId write FpluginId;
    property pointId: string read FpointId write FpointId;
  end;

  TModelExtensionPoint = class(TObject)
  private
    Fdocumentation: TModelDocumentation;
    FextensionMultiplicity: string;
    Fid: string;
    FparamDefs: ILinkedList;
    FparentPluginId: string;
    FparentPointId: string;
  public
    constructor Create;
    destructor Destroy; override;
    property documentation: TModelDocumentation read Fdocumentation write
        Fdocumentation;
    property extensionMultiplicity: string read FextensionMultiplicity write
        FextensionMultiplicity;
    property id: string read Fid write Fid;
    property paramDefs: ILinkedList read FparamDefs write FparamDefs;
    property parentPluginId: string read FparentPluginId write FparentPluginId;
    property parentPointId: string read FparentPointId write FparentPointId;
  end;

  TModelLibrary = class(TObject)
  private
    Fdocumentation: TModelDocumentation;
    F_exports: IStrLinkedList;
    Fid: string;
    FisCodeLibrary: Boolean;
    Fpath: string;
    Fversion: TVersion;
  public
    constructor Create;
    destructor Destroy; override;
    procedure setCodeLibrary(Value: string);
    procedure Setversion(const Value: string);
    property documentation: TModelDocumentation read Fdocumentation write
        Fdocumentation;
    property _exports: IStrLinkedList read F_exports;
    property id: string read Fid write Fid;
    property isCodeLibrary: Boolean read FisCodeLibrary write FisCodeLibrary;
    property path: string read Fpath write Fpath;
    property version: TVersion read Fversion;
  end;

  TModelParameter = class(TObject)
  private
    Fdocumentation: TModelDocumentation;
    Fid: string;
    Fparams: ILinkedList;
    Fvalue: string;
  public
    constructor Create;
    destructor Destroy; override;
    property documentation: TModelDocumentation read Fdocumentation write
        Fdocumentation;
    property id: string read Fid write Fid;
    property params: ILinkedList read Fparams;
    property value: string read Fvalue write Fvalue;
  end;

  TModelParameterDef = class(TObject)
  private
    FcustomData: string;
    Fdocumentation: TModelDocumentation;
    Fid: string;
    Fmultiplicity: string;
    FparamDefs: ILinkedList;
    F_type: string;
  public
    constructor Create;
    destructor Destroy; override;
    property customData: string read FcustomData write FcustomData;
    property documentation: TModelDocumentation read Fdocumentation write
        Fdocumentation;
    property id: string read Fid write Fid;
    property multiplicity: string read Fmultiplicity write Fmultiplicity;
    property paramDefs: ILinkedList read FparamDefs;
    property _type: string read F_type write F_type;
  end;

  TModelPluginManifest = class (TObject)
  private
    Fattributes: ILinkedList;
    FdocsPath: string;
    Fdocumentation: TModelDocumentation;
    FextensionPoints: ILinkedList;
    Fextensions: ILinkedList;
    Fid: string;
    Flibraries: ILinkedList;
    Fprerequisites: ILinkedList;
    Fvendor: string;
    Fversion: TVersion;
  public
    constructor Create;
    destructor Destroy; override;
    procedure Setversion(const Value: string);
    property attributes: ILinkedList read Fattributes;
    property docsPath: string read FdocsPath write FdocsPath;
    property documentation: TModelDocumentation read Fdocumentation write
        Fdocumentation;
    property extensionPoints: ILinkedList read FextensionPoints;
    property extensions: ILinkedList read Fextensions;
    property id: string read Fid write Fid;
    property libraries: ILinkedList read Flibraries;
    property prerequisites: ILinkedList read Fprerequisites;
    property vendor: string read Fvendor write Fvendor;
    property version: TVersion read Fversion;
  end;

  TModelPluginDescriptor = class(TModelPluginManifest)
  private
    FpluginClassName: string;
    procedure SetpluginClassName(const Value: string);
  public
    property pluginClassName: string read FpluginClassName write SetpluginClassName;
  end;

  TModelPluginFragment = class(TModelPluginManifest)
  private
    Fmatch: string;
    FpluginId: string;
    FpluginVersion: TVersion;
  public
    procedure SetpluginVersion(const Value: string);
    property match: string read Fmatch write Fmatch;
    property pluginId: string read FpluginId write FpluginId;
    property pluginVersion: TVersion read FpluginVersion;
  end;

  TModelPrerequisite = class(TObject)
  private
    Fdocumentation: TModelDocumentation;
    Fid: string;
    FisExported: Boolean;
    FisOptional: Boolean;
    Fmatch: string;
    FpluginId: string;
    FpluginVersion: TVersion;
  public
    constructor Create;
    destructor Destroy; override;
    procedure SetpluginVersion(const Value: string);
    property documentation: TModelDocumentation read Fdocumentation write
        Fdocumentation;
    property id: string read Fid write Fid;
    property isExported: Boolean read FisExported write FisExported;
    property isOptional: Boolean read FisOptional write FisOptional;
    property match: string read Fmatch write Fmatch;
    property pluginId: string read FpluginId write FpluginId;
    property pluginVersion: TVersion read FpluginVersion;
  end;

  TModelManifestInfo = class(TObject)
  private
    FId: string;
    Fmatch: string;
    FpluginId: string;
    FpluginVersion: TVersion;
    Fvendor: string;
    Fversion: TVersion;
  public
    constructor Create;
    destructor Destroy; override;
    procedure setVersion(value: string);
    procedure setPluginVersion(value: string);
    property Id: string read FId write FId;
    property match: string read Fmatch write Fmatch;
    property pluginId: string read FpluginId write FpluginId;
    property pluginVersion: TVersion read FpluginVersion;
    property vendor: string read Fvendor write Fvendor;
    property version: TVersion read Fversion;
  end;


implementation

constructor TModelAttribute.Create;
begin
  Fattributes := Rcl.TLinkedList.Create();
end;

destructor TModelAttribute.Destroy;
begin
  if Fdocumentation <> nil then
    Fdocumentation.Free;
  Fdocumentation := nil;
  inherited;
end;

constructor TModelDocumentation.Create;
begin
  Freferences := Rcl.TLinkedList.Create();
end;

constructor TModelExtension.Create;
begin
  Fparams := Rcl.TLinkedList.Create();
end;

destructor TModelExtension.Destroy;
begin
  if Fdocumentation <> nil then
    Fdocumentation.Free;
  Fdocumentation := nil;
  inherited;
end;

constructor TModelExtensionPoint.Create;
begin
  FparamDefs := Rcl.TLinkedList.Create();
  FextensionMultiplicity := EXT_MULT_ONE;
end;

destructor TModelExtensionPoint.Destroy;
begin
  if Fdocumentation <> nil then
    Fdocumentation.Free;
  Fdocumentation := nil;
  inherited;
end;

constructor TModelLibrary.Create;
begin
  F_exports := Rcl.TStrLinkedList.Create();
end;

destructor TModelLibrary.Destroy;
begin
  if Fdocumentation <> nil then
    Fdocumentation.Free;
  Fdocumentation := nil;
  inherited;
end;

procedure TModelLibrary.setCodeLibrary(Value: string);
begin
  FisCodeLibrary := AnsiSameText('code', Value);
end;

procedure TModelLibrary.Setversion(const Value: string);
begin
  Fversion := TVersion.parse(Value);
end;

constructor TModelParameter.Create;
begin
  Fparams := Rcl.TLinkedList.Create();
end;

destructor TModelParameter.Destroy;
begin
  if Fdocumentation <> nil then
    Fdocumentation.Free;
  Fdocumentation := nil;
  inherited;
end;

constructor TModelParameterDef.Create;
begin
  multiplicity := MULT_ONE;
  _type:= TYPE_STRING;
  FparamDefs := Rcl.TLinkedList.Create();
end;

destructor TModelParameterDef.Destroy;
begin
  if Fdocumentation <> nil then
    Fdocumentation.Free;
  Fdocumentation := nil;
  inherited;
end;

constructor TModelPrerequisite.Create;
begin
  Fmatch := 'compatible';
end;

destructor TModelPrerequisite.Destroy;
begin
  if Fdocumentation <> nil then
    Fdocumentation.Free;
  Fdocumentation := nil;
  inherited;
end;

procedure TModelPrerequisite.SetpluginVersion(const Value: string);
begin
  FpluginVersion := TVersion.parse(Value);
end;

constructor TModelPluginManifest.Create;
begin
  Fattributes := Rcl.TLinkedList.Create();
  Fextensions := Rcl.TLinkedList.Create();
  FextensionPoints := Rcl.TLinkedList.Create();
  Flibraries := Rcl.TLinkedList.Create();
  Fprerequisites := Rcl.TLinkedList.Create();
end;

destructor TModelPluginManifest.Destroy;
begin
  Fattributes.Clear;
  Fattributes := nil;
  Fextensions.Clear;
  Fextensions := nil;
  FextensionPoints.Clear;
  FextensionPoints := nil;
  Flibraries.Clear;
  Flibraries := nil;
  Fprerequisites.Clear;
  Fprerequisites := nil;

  if Fdocumentation <> nil then
    Fdocumentation.Free;
  Fdocumentation := nil;

  if Fversion <> nil then
    Fversion.Free;
  Fversion := nil;
  inherited;
end;

{ TModelManifestInfo }

procedure TModelPluginManifest.Setversion(const Value: string);
begin
  Fversion := TVersion.parse(Value);
end;

procedure TModelPluginFragment.SetpluginVersion(const Value: string);
begin
  FpluginVersion := TVersion.parse(Value);
end;

procedure TModelPluginDescriptor.SetpluginClassName(const Value: string);
begin
  FpluginClassName := Value;
end;

constructor TModelManifestInfo.Create;
begin
  Fmatch := MATCH_COMPATIBLE;
end;

destructor TModelManifestInfo.Destroy;
begin
  if FVersion <> nil then
    FreeAndNil(FVersion);
  inherited;
end;

procedure TModelManifestInfo.setPluginVersion(value: string);
begin
  FpluginVersion := TVersion.parse(value);
end;

procedure TModelManifestInfo.setVersion(value: string);
begin
  Fversion := TVersion.parse(value);
end;

end.
